package com.tech.controller.sys;

import com.alibaba.dubbo.config.annotation.Reference;
import com.tech.pojo.SysUser;
import com.tech.response.BaseResponse;
import com.tech.service.SysUserService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @Description: 登录相关操作
 * @Author: zl
 * @Date: 2019/1/6 12:03
 */
@Controller
@RequestMapping("/sys")
public class LoginController {

    @Reference
    private SysUserService sysUserService;

    @RequestMapping(value = "/login",method = RequestMethod.POST)
    @ResponseBody
    public void login(String userName,String passWord){
        
        BaseResponse<Boolean> response = new BaseResponse<>();
        // 根据用户名密码进行查询 --》 当前限定用户名只能为邮箱地址
        SysUser user = sysUserService.getSysUserInfo(userName);
        if (user == null) {
            response.setMsg("用户名密码不存在");
            response.putSuccess(false);
        } else {
            if (passWord.equals(user.getPassword())) {
                response.setMsg("登录成功");
                response.putSuccess(true);
            } else {
                response.setMsg("用户名或密码错误");
                response.putSuccess(false);
            }
        }
    }
}
